{% extends "templates/atnet_base.html" %}

{% block csslink %}
		{{ super() }}
<script src="/media/js/jquery.js"></script>

{% include 'templates/includes_datatable.html' %}
{% include 'templates/includes_jquery_ui.html' %}
<script src="/media/js/form_popup.js"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
	var wasAction = false;
	
	$('#fundraising').dataTable({
		"bPaginate": false,
		"bLengthChange": false,
		"bFilter": true,
		"bSort": true,
		"bInfo": false,
		"bAutoWidth": false,
		"oLanguage": {
            "sUrl": "/media/js/dataTables.{{ app_user.lang }}.txt"
        },
		"bProcessing": true,
		"sAjaxSource": "{{ uri_for('fundraising', imm_id=immeuble.key().id(), command='list_json') }}",
		"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
			$('td:eq(5)', nRow).html('<nobr><a href="javascript:void(0);" id="' + aData[5] + '" class="edit">{{ _("Edit") }}</a> || <a href="{{ uri_for('reports_web', imm_id=immeuble.key().id(), command='fundraising') }}' + aData[5]  + '/" class="print" target="_blank">{{ _("Preview") }}</a> || <a href="{{ uri_for('reports_web', imm_id=immeuble.key().id(), command='fundraising') }}' + aData[5]  + '/?format=pdf" class="print" target="_blank">{{ _("Print") }}</a> ||  <a href="javascript:void(0);" id="' + aData[5] + '" class="commit">{{ _("Commit transaction") }}</a></nobr>');
		},
	});
	
	$('#add-fr').live('click', function(){
		$(this).LaunchPopup(
				{
					TableId: '#fundraising, #budget-sum',
					DivId: '#dialog-form',
					FormId: '#generated-form',
					UrlForm: "{{ uri_for('fundraising', imm_id=immeuble.key().id(), command='add') }}",
					Mode: 'add',
					Title: '{{ _("Add fundraising") }}',
					UrlReturn: "{{ uri_for('fundraising', imm_id=immeuble.key().id(), command='list') }}"
				}
			)
	});
	
	$('#fundraising tbody tr a').live('click', function(e) {
		if ($(this).attr('class') == 'edit') {
		$(this).LaunchPopup(
				{
					TableId: '#fundraising, #budget-sum',
					DivId: '#dialog-form',
					FormId: '#generated-form',
					UrlForm: "{{ uri_for('fundraising', imm_id=immeuble.key().id(), command='edit') }}" + e.target.id + "/",
					Mode: 'edit',
					Title: '{{ _("Edit fundraising") }}',
					UrlReturn: "{{ uri_for('fundraising', imm_id=immeuble.key().id(), command='list') }}"
				}
			)
		}
		if ($(this).attr('class') == 'commit') {
			$(this).LaunchPopup(
					{
						TableId: '#fundraising, #budget-sum',
						DivId: '#dialog-form',
						FormId: '#generated-form',
						UrlForm: "{{ uri_for('fundraising', imm_id=immeuble.key().id(), command='commit') }}" + e.target.id + "/",
						Mode: 'edit',
						Title: '{{ _("Commit fundraising") }}',
						UrlReturn: "{{ uri_for('fundraising', imm_id=immeuble.key().id(), command='list') }}"
					}
				)
			}
	});
	
	$('#budget-sum').dataTable({
		"bPaginate": false,
		"bLengthChange": false,
		"bFilter": false,
		"bSort": false,
		"bInfo": false,
		"bAutoWidth": true,
		"oLanguage": {
            "sUrl": "/media/js/dataTables.{{ app_user.lang }}.txt"
        },
		"bProcessing": true,
		"sAjaxSource": "{{ uri_for('creation_budget', imm_id=immeuble.key().id(), command='sum_json') }}"
	});
});
</script>
{% endblock %}

{% block title %} 
	{{ title }}
{% endblock %}

{% block header %}
{{ header }}
{% endblock %}

{% block login%}
{% if show_login %}
{{ super() }}
{% endif %}
{% endblock%}

{% block navigation %}
{% if not show_login %}
{{ super() }}
{% endif %}
{% endblock %}

{% block section_menu %}
{% include 'templates/includes_vie_de_la_copropriete.html' %}
{% endblock %}

{% block main_content %}
<p>
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="budget-sum"  width="50%">
		<thead>
			<tr>
				<th><nobr>{{ _(fields.period) }}</nobr></th>
				<th><nobr>{{ _(fields.summary_amount) }}</nobr></th>
				<th><nobr>{{ _(fields.fundrised) }}</nobr></th>
				<th><nobr>{{ _(fields.received) }}</nobr></th>
			</tr>
		</thead>
		<tbody>
		</tbody>
		<tfoot>
			<tr>
				<th colspan="4"></th>
			</tr>
		</tfoot>
		
	</table>
	
	<p><a href="javascript:void(0);" id="add-fr">{{ _('Add fundraising') }}</a></p>
	<div id="demo">
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="fundraising" width="100%">
		<thead>
			<tr>
				<th>{{ _(fields.period) }}</th>
				<th>{{ _(fields.deadline) }}</th>
				<th>{{ _(fields.type) }}</th>
				<th>{{ _(fields.desc) }}</th>
				<th>{{ _(fields.amount) }}</th>
				<th width="20"></th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td colspan="11" class="dataTables_empty">{{ _('Loading data from server') }}</td>
			</tr>
		</tbody>
		<tfoot>
			<tr>
				<th>{{ _(fields.period) }}</th>
				<th>{{ _(fields.deadline) }}</th>
				<th>{{ _(fields.type) }}</th>
				<th>{{ _(fields.desc) }}</th>
				<th>{{ _(fields.amount) }}</th>
				<th></th>
			</tr>
		</tfoot>
	</table>
	</div>
	{% include 'templates/includes_popup_form.html' %}
</p>
<script>
$(function() {
	var user_lang = "{{ app_user.lang }}";
	if (user_lang == "en") { user_lang = "en-GB" };
	$.datepicker.setDefaults( $.datepicker.regional[ user_lang ] );
	
	$("#deadline").live("focus", function() {
	    $(this).datepicker({
	        inline: true 
	    });
	});
});
</script>
{% endblock %}
